-
Notifications
You must be signed in to change notification settings - Fork 213
Add formatting and validation for free-form fields #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
269b060
to
305ff32
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
1e7e79e
to
4b726f2
Compare
4b726f2
to
7e9f2be
Compare
@tadasant please review. |
[EDIT: see comment below...] I think where possible, I'd want to push this into the JSON schema spec as much as possible - this means:
Of course there will be exceptions to this where we really can't do it with JSON schema. But a lot of this I think could be replicated with e.g. length or regex requirements on the JSON schema etc. |
Hmm actually just read up on #97, and that maybe we only want this to be on the official registry API spec (rather than the generic registry API spec). Based on @.tadasant's comment:
I guess in that case the approach you've gone for here is fine - I'll leave it up to @tadasant to decide / review :) |
@domdomegg - isn't it preferred to still have the validation in the schema even if it's just for registry-server.json? |
@rdimitrov possibly true? I guess then it'd be harder to take the official-registry-api-schema.json and turn it into the registry-api-schema.json. But maybe this is fine and/or we shouldn't maintain them this way. |
@domdomegg / @tadasant can we conclude on the discussion whether we want to add the validation in the spec and let huma handle it or we should go ahead with the code based validation? It's fine if we need more time to think it through. |
Sorry I'm well behind on reviews and discussions and trying to focus where I'm blocking @domdomegg - trust his call on this one if he wants to jump ahead and get this merged (otherwise I will get to this eventually, just will be slow) This is correct:
The intent is for this formatting/validation to only apply to the official registry. Most importantly at publication-time (we don't want people publishing data that is noncomformant to these expectations) I haven't yet formed an opinion on how that cascades to the implementation here |
No worries @tadasant, take your time. @domdomegg you can also review if you want to. |
Okay I've had a think about this, and my conclusion is that I think it doesn't matter too much either way 😅 I have a weak preference towards doing it as schema annotations in huma, rather than custom code validations. I think this documents it better for users of the API, and usually is less verbose/puts all the schema info in one place. I'd be happy to accept this PR, or one doing it with schema annotations, once the code is cleaned up a little (e.g. linting and tests pass). @Avish34 are you good to take up implementing it one of these ways, then pinging me once you have CI passing? |
Thanks @domdomegg , Yes I'm picking up the implementation. Sure!! |
d3d9a13
to
5e22e9f
Compare
@domdomegg CI is passing now. Can you start reviewing please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking mostly good, with a few comments - can merge after they are resolved :)
I will address the comments, thanks for reviewing @domdomegg. Btw is this https://github.com/modelcontextprotocol/registry/blob/main/docs/server-json/schema.json are you talking about in the comments right? |
@Avish34 yeah for the comments like 'I think this could be made a requirement on the main server.json schema' I think we'd want to add them to the server.json schema and as annotations on the Huma API probably here following these docs. |
@domdomegg Got it. You mean adding minLength and maxLength to the openapi schema of server.json for the relevant fields and adding the same annotation to model.go to allow huma to validate. Is the understanding right? |
Yes that's correct, and similar for other validations that should be universal to server.json (i.e. not specific to the official MCP registry) |
5e22e9f
to
2dde049
Compare
@domdomegg I have added the validation in the schema for server.json and annotations in model.go, I tried enabling huma validation but it's failing some UTs. I think enabling I can take up in next PR if not a problem, we can merge this till then. |
- Fix typo: RespositoryValidator -> RepositoryValidator - Align constants with schema limits (200 for name, 100 for description) - Remove redundant validations handled by Huma (name required, length checks) - Simplify repository validation empty check - Remove unused error constants and test cases
Thanks a lot @domdomegg !! |
The changes are intended to create validators for all the free-form fields. Please find the details of the validation of different field below.
TODOs
Motivation and Context
The motivation was to make the code clean and add base code for more validator for different objects like Repository etc.
#97
How Has This Been Tested?
It's tested via UTs. Added UT's for all the validations.
Breaking Changes
Yes
Types of changes
Checklist
Additional context